package com.fengmi.controller;

import com.fengmi.entity.MallGoodsBrand;
import com.fengmi.service.MallGoodsBrandService;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: 施俊豪
 * Date: 2022/1/17 19:34
 * Note: 商品品牌控制器
 */
@CrossOrigin
@RequestMapping("brand")
@Api(description="商品品牌控制器")
@RestController
public class MallGoodsBrandController {
    @Autowired
    private MallGoodsBrandService mallGoodsBrandService;

    @ApiOperation("商品品牌条件查询+分页方法")
    @RequestMapping("/findGoodsBrand")
    public PageResult findGoodsBrand(@ApiParam("查询条件") @RequestBody MallGoodsBrand mallGoodsBrand,
                                     @ApiParam("当前页数")@RequestParam(value="pageNum",defaultValue = "1")String pageNum,
                                     @ApiParam("当前页数中的记录数")@RequestParam(value="pageSize",defaultValue = "5")String pageSize,
                                     @RequestHeader("token")String token){
        System.out.println("商品品牌条件查询+分页的token=====>"+token);
        PageResult<MallGoodsBrand> pageResult = mallGoodsBrandService.findGoodsBrand(pageNum, pageSize, mallGoodsBrand);
        return pageResult;
    }

    @ApiOperation("商品品牌添加")
    @RequestMapping("/addGoodsBrand")
    public InfoResult addGoodsBrand(@ApiParam("添加的商品品牌对象") @RequestBody MallGoodsBrand mallGoodsBrand,
                                    @RequestHeader("token")String token){
        System.out.println("添加商品品牌的token=====>"+token);
        InfoResult infoResult = mallGoodsBrandService.addGoodsBrand(mallGoodsBrand);
        return infoResult;
    }

    @ApiOperation("商品品牌修改")
    @RequestMapping("/updateGoodsBrand")
    public InfoResult updateGoodsBrand(@ApiParam("修改的商品品牌对象") @RequestBody MallGoodsBrand mallGoodsBrand,
                                       @RequestHeader("token") String token){
        System.out.println("修改商品品牌的token=====>"+token);
        return mallGoodsBrandService.updateGoodsBrand(mallGoodsBrand);
    }

    @ApiOperation("商品品牌删除")
    @DeleteMapping("/delGoodsBrand")
    public InfoResult delGoodsBrand(@ApiParam("删除的商品品牌集合")@RequestBody Integer[] ids,
                                    @RequestHeader("token") String token){
        System.out.println("删除商品品牌的token=====>"+token);
        return mallGoodsBrandService.deleteGoodsBrand(ids);
    }

    @ApiOperation("查询所有商品品牌")
    @RequestMapping("/findAllBrand")
    public InfoResult findAllBrand(@RequestHeader("token") String token){
        System.out.println("查询所有商品品牌的token:"+token);
        return mallGoodsBrandService.findBrandAll();
    }

}
